package com.wenwei.sharebox.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.activity.GoodsDetailsActivity;
import com.wenwei.sharebox.activity.ReturnGoodsActivity;
import com.wenwei.sharebox.adapter.ShareZuAdapter;
import com.wenwei.sharebox.base.BaseFragment;
import com.wenwei.sharebox.base.Constant;
import com.wenwei.sharebox.bean.UserShareBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/20.
 */
public class ShareRentFragment extends BaseFragment {
    @Bind(R.id.recycler)
    RecyclerView recycler;

    ShareZuAdapter mZuAdapter;
    @Override
    public View initView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.fragment_share_commont, null);
    }

    @Override
    protected void lazyload() {

    }

    @Override
    protected void initEvent() {
        super.initEvent();
        recycler.setLayoutManager(new LinearLayoutManager(mActivity));
        mZuAdapter = new ShareZuAdapter(new ShareZuAdapter.CallBack() {
            @Override
            public void onZuItemClick(UserShareBean.DataBean bean) {
                Bundle b1 = new Bundle();
                b1.putSerializable("bean",bean);
                goActivity(mActivity, ReturnGoodsActivity.class,b1);
            }

            @Override
            public void onZuReturnMoney(UserShareBean.DataBean bean) {
                goActivity(mActivity, ReturnGoodsActivity.class);
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
        getUserShareRent();
    }

    BaseSubscriber<UserShareBean> rentSubscriber;
    private void getUserShareRent(){
        rentSubscriber = new BaseSubscriber<UserShareBean>(mActivity) {
            @Override
            public void onSuccess(UserShareBean userShareBean) {
                mZuAdapter.setShareDataList(userShareBean.getData(),userShareBean.getTimestamp());
                recycler.setAdapter(mZuAdapter);
                mZuAdapter.notifyDataSetChanged();
            }
        };
        ApiManager.getInstance().getBuyAndRent(rentSubscriber,1,10, Constant.SHARE_TYPE_RENT);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
